package com.joysuch.wwyt.risk.repository;

import com.joysuch.wwyt.risk.entity.RiskDynamicConfig;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * @Author ZhaoQiuWei
 * @Date 2022/4/6 15:06
 */
public interface RiskDynamicConfigDao extends JpaRepository<RiskDynamicConfig, Long> {

    @Query(value = "select * from `wwyt_risk_dynamic_config` where process_id =?1 and type = ?2 and enable_flag =?3 and delete_flag = '0'", nativeQuery = true)
    List<RiskDynamicConfig> findByTypeAndEnableFlag(Long processId,int type, int enableFlag);

    @Query(value = "SELECT COUNT(*) FROM `wwyt_risk_dynamic_config` WHERE delete_flag = '0' AND process_id = ?1 AND option_type_name = ?2 AND option_param_id=?3 AND TYPE = ?4", nativeQuery = true)
    int countByProcessIdAndOptionTypeNameAndOptionParamIdAndType(Long processId, String optionTypeName, Long optionParamId, Integer type);

    @Query(value = "SELECT COUNT(*) FROM `wwyt_risk_dynamic_config` WHERE delete_flag = '0' AND process_id = ?1 AND option_type_name = ?2 AND option_param_id=?3 AND TYPE = ?4 AND id !=?4", nativeQuery = true)
    int countByProcessIdAndOptionTypeNameAndOptionParamIdAndTypeAndIdNotEq(Long processId, String optionTypeName, Long optionParamId, Integer type, Long id);

    @Query(value = "SELECT * FROM wwyt_risk_dynamic_config WHERE type =0 AND delete_flag = '0' AND enable_flag = ?1 AND option_param_name =?2 AND tenent_id =?3 AND org_code LIKE ?4% limit 1", nativeQuery = true)
    RiskDynamicConfig getMhPointConfigByEnableFlagAndParam(Integer enableFlag, String param,Long tenentId,String orgCode);

}
